package yue.shen.android.demo.view.banner

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

class AutoLoopViewPager : ViewPager {

    private var scrollable = true

    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(ev: MotionEvent?): Boolean {
        if (this.scrollable) {
            if (currentItem == 0 && childCount == 0) {
                return false
            }
            return super.onTouchEvent(ev)
        } else {
            return false
        }
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        if (this.scrollable) {
            if (currentItem == 0 && childCount == 0) {
                return false
            }
            return super.onInterceptTouchEvent(ev)
        } else {
            return false
        }

    }

}